package com.blackhorse.stream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

/**
 * 消息生产者入门案例
 * 1.引入依赖
 * 2.配置yml文件
 * 3.发送消息需要定义一个通道接口，通过接口内置的messageChannel
 * SpringCloudStream已经写好这个接口 Source
 * 4.@EnableBinding：绑定对应通道
 * 5.发送消息通过messageChannel发送
 * 如果需要messageChannel，是通过绑定的内置接口获取的
 */
//@EnableBinding(Source.class)//工具类代替
@SpringBootApplication
public class ProducerApplication /*implements CommandLineRunner*/ {

    //@Autowired
    //private MessageChannel output;//工具类代替

//    @Override
//    public void run(String... args) throws Exception {//工具类代替
//        //发送消息 MessageBuilder工具类创建消息
//        output.send(MessageBuilder.withPayload("消息生产者发送的消息").build());
//    }

    //以命令行形式运行案例
    public static void main(String[] args) {
        SpringApplication.run(ProducerApplication.class);
    }
}
